<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : link.class.php   FILE_PATH : E:\www\\classes\application\link.class.php
 * 友情链接管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Feb 15 17:41:56 CST 2008
 */

class LinkClass extends FrameWork {
	var $obj_config;
	/**
	 * 保存参数配置信息
	 * @author  
	 * @param  
	 * @return bool
	 */
	function setSave($input_param){
		require_once('inifileoperate.class.php');
		$this->obj_config = new IniFileOperate("../config/config.ini.php");
		$this->obj_config->setIniFile("link","pic_width",intval($input_param["pic_width"]));
		$this->obj_config->setIniFile("link","pic_height",intval($input_param["pic_height"]));
		return true;
	}
	
	/**
	 * 友情链接列表
	 * @author  
	 * @param  
	 * @return bool
	 */
	function listLink($condition,&$obj_page){
		$conditionstr = $this->_conditionSearch($condition);
		$link_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "link");
		return $link_array;
	}
	
	/**
	 * 构造搜索条件
	 * @author     
	 * @param  
	 * @return 
	 */
	function _conditionSearch($condition){
		$conditionstr = '';
		
		/*是否关闭*/
		if ($condition['close'] != ''){
			$conditionstr .= " and link_close = '".$condition['close']."'";
		}
		
		/*是否删除*/
		if ($condition['del'] != ''){
			$conditionstr .= " and link_state = '".$condition['del']."'";
		}else {
			$conditionstr .= " and link_state = '0'";
		}
		
		/*选择显示类型*/
		if ($condition['type'] == '0') {
			$conditionstr .= " and link_type = '0'";
		}elseif ($condition['type'] == '1'){
			$conditionstr .= " and link_type = '1'";
		}
		
		
		/*排序*/
		if ($condition['order'] == 'asc'){
			$conditionstr .= " order by link_sort asc ";
		}else if ($condition['order'] == 'desc'){
			$conditionstr .= " order by link_sort desc ";
		}
		
		return $conditionstr;
	}
	
	/**
	 * 新增链接
	 * @author     
	 * @param  
	 * @return bool
	 */
	function addLink($input_param){
		if (is_array($input_param)){
			$value_array = array();
			foreach ($input_param as $k => $v){
				$value_array[$k] = $v;
			}
			$insert_rs = $GLOBALS['db']->InsertRow($value_array, 'link', 'link_id');
			if ($insert_rs !== true) {
				return false;
			}
			return true;
		}
		return false;
	}
	
	/**
	 * 取链接记录
	 * @author 
	 * @param  
	 * @return array
	 */
	function getOneLink($id){
		return $GLOBALS['db']->GetOneRow($id,'link','link_id');
	}
	
	/**
	 * 新增链接
	 * @author     
	 * @param  
	 * @return bool
	 */
	function modiLink($input_param){
		if (is_array($input_param)){
			$value_array = array();
			foreach ($input_param as $k => $v){
				$value_array[$k] = $v;
			}
			$insert_rs = $GLOBALS['db']->UpdateRow($value_array['link_id'],$value_array, 'link', 'link_id');
			if ($insert_rs !== true) {
				return false;
			}
			return true;
		}
		return false;
	}
	
	/**
	 * 删除信息
	 * @author     
	 * @param  
	 * @return bool
	 */
	function delLink($link_id){
		if (intval($link_id) > 0){
			$GLOBALS['db']->DeleOneRow(intval($link_id),'link','link_id');
		}
		return true;
	}
}
?>